package leetcode_字符串._12中心扩散法;

/**
 *  回文字串
 *  动态规划，做法跟 6 一样
 */
public class _647 {
    public static void main(String[] args) {

    }

    public int countSubstrings(String s) {
        int len = s.length();
        if (len < 2) {
            return len;
        }
        int ans = 0;
        char[] c = s.toCharArray();
        boolean[][] dp = new boolean[len][len];
        for (int i = len - 1; i >= 0; --i) {
            for (int j = i; j < len; ++j) {
                if (i == j || (c[i] == c[j] && (j == i + 1 || dp[i + 1][j - 1]))) {
                    dp[i][j] = true;
                    ++ans;
                }
            }
        }
        return ans;
    }
}
